package com.hz.ruoyistorage.controller;


import com.hz.rouyigonggong.utils.ResultJSON;
import com.hz.ruoyistorage.domain.LgColdStorage;
import com.hz.ruoyistorage.domain.LgUnitSe;
import com.hz.ruoyistorage.service.LgUnitSeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @version 1.0
 * @Author gj
 * @Date 2025/3/8 15:29
 * @注释
 */
@RestController
@RequestMapping("/unitSe")
public class LgUnitSeController {
    @Autowired
    private LgUnitSeService lgUnitSeService;

//    @RequiresPermissions("storage:unit:getAll")
    @RequestMapping("/getList")
    public ResultJSON getList(String unitName,
                             String beginTime,
                             String endTime, Integer pageNum, Integer pageSize){

        Integer firstNum = (pageNum-1)*pageSize;
        Integer secondNum = pageSize;


        //完成分页
        return ResultJSON.success(lgUnitSeService.getReallyList(unitName,
                beginTime,
                endTime,
                firstNum,secondNum));

    }
//    @RequiresPermissions("storage:unit:getAll")
    @RequestMapping("/getTotal")
    public ResultJSON getTotal(String unitName,
                              String beginTime,
                              String endTime){
        return ResultJSON.success(lgUnitSeService.getCount(unitName,
                beginTime,
                endTime));
    }
//    @RequiresPermissions("storage:unit:getAll")
    @GetMapping(value = "/{unitId}")
    public ResultJSON getUnitById(@PathVariable Integer unitId){

        return ResultJSON.success(lgUnitSeService.getById(unitId));
    }
    //新增
//    @RequiresPermissions("storage:unit:add")
    @RequestMapping("/addUnit")
    public ResultJSON addUnit(@RequestBody LgUnitSe lgUnitSe){
        return
                ResultJSON.success(lgUnitSeService.save(lgUnitSe));
    }
    //修改
//    @RequiresPermissions("storage:unit:update")
    @RequestMapping("/updateUnit")
    public ResultJSON updateUnit(@RequestBody LgUnitSe lgUnitSe){
        return ResultJSON.success(lgUnitSeService.updateById(lgUnitSe));
    }
//    @RequiresPermissions("storage:unit:delete")
    @DeleteMapping("/{unitIds}")
    public AjaxResult delUnit(@PathVariable String[] unitIds)
    {
        return AjaxResult.success(lgUnitSeService.deleteBatchIds(unitIds));

    }
    //导出
    @RequiresPermissions("storage:unit:export")
    @Log(title = "单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgUnitSe lgUnitSe)
    {

        List<LgUnitSe> list = lgUnitSeService.list(null);
        ExcelUtil<LgUnitSe> util = new ExcelUtil<LgUnitSe>(LgUnitSe.class);
        util.exportExcel(response, list, "单位数据");
    }
}
